package cn.org.bjca.seal.esspdf.client.test;

import cn.org.bjca.anysign.client.CSecurity.CloudSecurityEngine;
import cn.org.bjca.anysign.client.CSecurity.CloudSecurityEngineImpl;
import cn.org.bjca.anysign.client.ISecurity.PDFSecurityEngine;
import cn.org.bjca.anysign.client.ISecurity.PDFSecurityEngineImpl;
import cn.org.bjca.anysign.client.exceptions.SVSConnectException;
import cn.org.bjca.anysign.client.net.exceptions.ParameterInvalidException;
import cn.org.bjca.anysign.client.net.exceptions.ParameterOutRangeException;
import cn.org.bjca.anysign.client.net.exceptions.UnkownException;
import cn.org.bjca.anysign.client.security.SecurityEngineDeal;
import cn.org.bjca.anysign.datasign.model.DataSignInfo;
import cn.org.bjca.anysign.datasign.model.DataSignInfo2;
import cn.org.bjca.anysign.model.AnywriteSignInfo;
import cn.org.bjca.anysign.model.p2p.PeerCreditInfo;
import cn.org.bjca.anysign.model.p2p.PeerCreditInfoListPdf;
import cn.org.bjca.anysign.model.p2p.PeerCreditSignInfo;
import cn.org.bjca.anysign.model.p2p.SignExtInfo;
import cn.org.bjca.cloud.model.CloudUnitSignForCCdoe;
import cn.org.bjca.cloud.model.CloudUnitSignInfo;
import cn.org.bjca.common.model.*;
import cn.org.bjca.pdf.model.DocumentType;
import cn.org.bjca.pdf.model.PDFGenerateInfo;
import cn.org.bjca.pdf.model.PDFGenerateList;
import cn.org.bjca.pdf.model.PDFMergeInfo;
import cn.org.bjca.seal.esspdf.client.message.VerifyMessage;
import cn.org.bjca.seal.esspdf.client.message.VerifyResult;
import cn.org.bjca.seal.esspdf.client.utils.Base64Encoder;
import cn.org.bjca.seal.esspdf.client.utils.ClientUtil;
import cn.org.bjca.seal.esspdf.client.utils.JsonMapper;
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.util.*;

/***************************************************************************
 * <pre>
 *     V1.3.4适配单元测试
 * </pre>
 * @文件名称: AnyWriteAdapterClientToolTest
 * @包路径： cn.org.bjca.seal.esspdf.client.test
 * @版权所有： 北京数字认证股份有限公司 (C) 2017
 *
 * @类描述:
 * @版本: V2.0
 * @创建人： 费玥
 * @创建时间： 20:15
 *
 ***************************************************************************/
public class AnyWriteAdapterClientToolTest extends AnyWriteBaseTest {

	@Before
	public void initAdapterServerParams() throws Exception {
		SecurityEngineDeal.setProfilePath("C:\\BJCAROOT");
		sed = SecurityEngineDeal.getInstance();
		CloudSecurityEngine cloudSecurityEngine = new CloudSecurityEngineImpl("AnySignDefault");
		PDFSecurityEngine pdfSecurityEngine = new PDFSecurityEngineImpl("AnySignDefault");
		sed.setCloudSecurityEngine(cloudSecurityEngine);
		sed.setSecurityEngineDealIF(pdfSecurityEngine);
	}

	/**
	 *
	 * <p>老接口一码多签生成挑战码</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteListPDFGenerateChallengeCodeOriginal() throws Exception {
		PeerCreditInfoListPdf peerCreditInfoListPdf = new PeerCreditInfoListPdf();
		peerCreditInfoListPdf.setSignerName("费玥");
		peerCreditInfoListPdf.setCacheCycime(6000);
		peerCreditInfoListPdf.setSignerPhoneNum("17701085294");
		List<GeneratePDFInfo> generatePDFInfoList = new ArrayList<GeneratePDFInfo>();
		final int SIGN_NUM = 5;
		for (int i = 0; i < SIGN_NUM; i++) {
			GeneratePDFInfo generatePDFInfo = new GeneratePDFInfo();
			generatePDFInfo.setDocContent(ClientUtil.readFileToByteArray(new File(testPdfFilePath)));
			generatePDFInfo.setDocumentExtType(DocumentExtType.PDF);
			generatePDFInfoList.add(generatePDFInfo);
		}
		peerCreditInfoListPdf.setGeneratePDFInfoList(generatePDFInfoList);
		List<KWRuleInfo> kwRuleInfoList = new ArrayList<KWRuleInfo>();
		for (int i = 0; i < SIGN_NUM; i++) {
			KWRuleInfo kwRuleInfo = new KWRuleInfo();
			kwRuleInfo.setPageno("1");
			kwRuleInfo.setKWPos("1");
			kwRuleInfo.setKW("的");
			kwRuleInfo.setKWOffset("100");
			kwRuleInfo.setKWXOffset("100");
			kwRuleInfo.setKWYOffset("100");
			kwRuleInfoList.add(kwRuleInfo);
		}
		SignExtInfo signExtInfo = new SignExtInfo();
		signExtInfo.setFontColor("blue");
		signExtInfo.setBussChannel("666666");
		signExtInfo.setFontStyle(FontStyle.MSYH);

		peerCreditInfoListPdf.setSignExtInfo(signExtInfo);
		peerCreditInfoListPdf.setKwRuleInfoList(kwRuleInfoList);

		AnySignOutput anySignOutput = sed.getCloudSecurityEngine().excuteChallengeCodeForP2PByListPdf(peerCreditInfoListPdf);
		System.out.println("状态码：" + anySignOutput.getStatusId());
		System.out.println("状态信息:" + errorCode2Info(anySignOutput.getStatusId()));
		Assert.assertEquals(anySignOutput.getStatusId(), 0);
		System.out.println("成功");
		System.out.println(anySignOutput.getChallengeCode());
		System.out.println(anySignOutput.getTransID());

	}

	/**
	 *
	 * <p>老接口一码一签生成挑战码</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteGenerateChallengeCodeOriginal() throws Exception {
		PeerCreditInfo peerCreditInfo = new PeerCreditInfo();
		peerCreditInfo.setSignerName("费玥");
		peerCreditInfo.setSignerPhoneNum("17701085294");
		peerCreditInfo.setSignerIDCardNum("110226198601030001");
		GeneratePDFInfo generatePDFInfo = new GeneratePDFInfo();
		generatePDFInfo.setDocumentExtType(DocumentExtType.PDF);
		generatePDFInfo.setDocContent(ClientUtil.readFileToByteArray(new File(testPdfFilePath)));
		peerCreditInfo.setGeneratePDFInfo(generatePDFInfo);
		peerCreditInfo.setSignRuleType("0");// 客户端自定义关键字
		KWRuleInfo kwRuleInfo = new KWRuleInfo();
		kwRuleInfo.setKW("的");
		kwRuleInfo.setKWOffset("0");
		kwRuleInfo.setKWPos("1");
		kwRuleInfo.setPageno("1");
		peerCreditInfo.setKwRuleInfo(kwRuleInfo);

		List<AttachmentInfo> attachmentInfoLs = new ArrayList<AttachmentInfo>();
		//附件
		AttachmentInfo attachmentInfo = new AttachmentInfo();
		attachmentInfo.setEvidence(false);
		attachmentInfo.setAttachContent(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
		attachmentInfo.setAttachType(DocumentExtType.IMAGEGIF);
		attachmentInfo.setAttach(true);
		//证据
		AttachmentInfo evidence = new AttachmentInfo();
		evidence.setEvidence(true);
		evidence.setAttach(false);
		evidence.setAttachContent(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
		evidence.setAttachType(DocumentExtType.IMAGEGIF);

		attachmentInfoLs.add(attachmentInfo);
		attachmentInfoLs.add(evidence);
		peerCreditInfo.setAttachmentInfoLs(attachmentInfoLs);

		SignExtInfo signExtInfo = new SignExtInfo();
		signExtInfo.setBussChannel("999999");
		peerCreditInfo.setSignExtInfo(signExtInfo);
		peerCreditInfo.setCacheCycime(6000);

		AnySignOutput anySignOutput = sed.getCloudSecurityEngine().excuteChallengeCodeForP2P(peerCreditInfo);
		System.out.println("状态码：" + anySignOutput.getStatusId());
		System.out.println("状态信息:" + errorCode2Info(anySignOutput.getStatusId()));
		Assert.assertEquals(anySignOutput.getStatusId(), 0);
		System.out.println("成功");
		System.out.println(anySignOutput.getChallengeCode());
		System.out.println(anySignOutput.getTransID());

	}

	/**
	 *
	 * <p>老接口一码一签签名</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteChallengeCodeSignOriginal() throws Exception {
		PeerCreditSignInfo peerCreditSignInfo = new PeerCreditSignInfo();
		peerCreditSignInfo.setTelephoneNum("17701085294");
		peerCreditSignInfo.setChallengeCode("391055");
		peerCreditSignInfo.setTransID("28410808-c24a-4f36-a779-ec70c0eee392");
		peerCreditSignInfo.setSignAlgType(SignAlgType.RSA);

		AnySignOutput anySignOutput = sed.getCloudSecurityEngine().excuteGetSignPDFForP2P(peerCreditSignInfo);
		System.out.println("状态码：" + anySignOutput.getStatusId());
		System.out.println("状态信息:" + errorCode2Info(anySignOutput.getStatusId()));
		Assert.assertEquals(anySignOutput.getStatusId(), 0);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteChallengeCodeSignOriginal.pdf"), anySignOutput.getPDFContent());

	}

	/**
	 *
	 * <p>老接口一码多签签名</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteChallengeCodeListSignOriginal() throws Exception {
		PeerCreditSignInfo peerCreditSignInfo = new PeerCreditSignInfo();
		peerCreditSignInfo.setTelephoneNum("17701085294");
		peerCreditSignInfo.setChallengeCode("371293");
		peerCreditSignInfo.setTransID("452b3802-d793-4533-b027-3224cdb93f2f");
		peerCreditSignInfo.setSignAlgType(SignAlgType.RSA);

		AnySignOutputList anySignOutputList = sed.getCloudSecurityEngine().excuteGetSignPDFForP2PByListPdf(peerCreditSignInfo);
		System.out.println("状态码:" + anySignOutputList.getStatusId());
		System.out.println("状态信息:" + errorCode2Info(anySignOutputList.getStatusId()));
		Assert.assertEquals(anySignOutputList.getStatusId(), 0);
		if (anySignOutputList.getStatusId() == 0) {
			System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
			for (int i = 0; i < anySignOutputList.getPDFContentList().size(); i++) {
				ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteChallengeCodeListSignOriginal_" + i + ".pdf"), anySignOutputList.getPDFContentList().get(i));
			}
		}

	}

	/**
	 * <p>挑战码签章老接口</p>
	 * @Description: 挑战码签章老接口
	 * @return:void
	 * @throws:
	 */
	@Test
	public void testAnyWriteChallengeCodeUnitSignOriginal() throws ParameterInvalidException, UnkownException, ParameterOutRangeException, SVSConnectException, IOException {
		CloudUnitSignForCCdoe cloudUnitSignForCCdoe = new CloudUnitSignForCCdoe();
		cloudUnitSignForCCdoe.setChallengeCode("253788");
		cloudUnitSignForCCdoe.setTransID("7a638686-a328-44f5-a8f3-c5144230d80e");
		cloudUnitSignForCCdoe.setSignAlgType(SignAlgType.RSA);
		cloudUnitSignForCCdoe.setTelephoneNum("17701085294");
		List<UnitSignInfo> unitSignInfoList = new ArrayList<UnitSignInfo>();
		for (int i = 0; i < 3; i++) {
			UnitSignInfo unitSignInfo = new UnitSignInfo();
			unitSignInfo.setOrganAppName("3F89508445039559");
			unitSignInfo.setSignRuleType("0");
			unitSignInfo.setSignImage(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
			KWRuleInfo kwRuleInfo = new KWRuleInfo();
			kwRuleInfo.setKW("的");
			kwRuleInfo.setKWOffset("0");
			kwRuleInfo.setKWPos("0");
			kwRuleInfo.setPageno("1");
			kwRuleInfo.setKWXOffset("0");
			kwRuleInfo.setKWXOffset("0");
			unitSignInfo.setKwRuleInfo(kwRuleInfo);
			unitSignInfoList.add(unitSignInfo);
		}
		cloudUnitSignForCCdoe.setUnitSignRuleLs(unitSignInfoList);

		AnySignOutput anySignOutput = sed.getCloudSecurityEngine().excuteGetCacheUnitSignPDF(cloudUnitSignForCCdoe);

		System.out.println("状态码：" + anySignOutput.getStatusId());
		System.out.println("状态信息:" + errorCode2Info(anySignOutput.getStatusId()));
		Assert.assertEquals(anySignOutput.getStatusId(), 0);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteChallengeCodeUnitSignOriginal.pdf"), anySignOutput.getPDFContent());
	}

	/**
	 *
	 * <p>老接口数据签名</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteDataSignOriginal() throws Exception {
		DataSignInfo dataSignInfo = new DataSignInfo();
		dataSignInfo.setEncData(ClientUtil.readFileToByteArray(new File(testEncDataPath + "数据签名加密包.txt")));
		int[] rv = new int[2];
		byte[] result = sed.getDataAnyWriteSign(dataSignInfo, rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteDataSignOriginal.txt"), result);

	}

	/**
	 *
	 * <p>老接口数据签名</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteDataSignOriginal2() throws Exception {
		DataSignInfo2 dataSignInfo2 = new DataSignInfo2();
		dataSignInfo2.setEncData(ClientUtil.readFileToByteArray(new File(testEncDataPath + "数据签名加密包.txt")));
		int[] rv = new int[2];
		byte[] result = sed.getDataAnyWriteSign2(dataSignInfo2, rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteDataSignOriginal2.txt"), result);

	}

	/**
	 *
	 * <p>老接口验证签名</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteDataSignVerifyOriginal() throws Exception {
		String contents = "x+uy4srUyrHKudPDuLTU07XE1K3OxLvyyuTI687EvP7Ct762";
		String pathname = outPdfsFilePath + "testAnyWriteDataSignOriginal.txt";
		int[] rv = new int[2];
		byte[] result = sed.verifyDataAnyWriteSign(ClientUtil.readFileToByteArray(new File(pathname)), new Base64Encoder().decode(contents), rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteDataSignVerifyOriginal.txt"), result);
	}

	/**
	 *
	 * <p>老加密包签名</p>
	 * @Description:
	 * @return void
	 * @throws
	 */
	@Test
	public void testAnyWriteSignByEncDataOriginal() throws Exception {
		byte[] encData = ClientUtil.readFileToByteArray(new File(testEncDataPath + "手写签名加密包.txt"));
		int[] rv = new int[2];
		byte[] pdf = sed.getPDFAnyWriteSign(encData, null, rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteSignByEncDataOriginal.pdf"), pdf);
	}

	/**
	 * <p>老加密包对象接口</p>
	 * @Description:
	 * @return:void
	 * @throws:
	 */
	@Test
	public void testAnyWriteSignByObjectOriginal() throws Exception {
		AnywriteSignInfo anywriteSignInfo = new AnywriteSignInfo();
		byte[] dataSource = ClientUtil.readFileToByteArray(new File(testEncDataPath + "手写签名加密包.txt"));
		byte[] dataSource2 = ClientUtil.readFileToByteArray(new File(testEncDataPath + "手写签名加密包.txt"));
		List<byte[]> dataSources = new ArrayList<byte[]>();
		dataSources.add(dataSource);
		dataSources.add(dataSource2);
		anywriteSignInfo.setDataSource(dataSources);
		Map<Integer, List<AttachmentInfo>> attachmentInfoMap = new HashMap<Integer, List<AttachmentInfo>>();
		List<cn.org.bjca.common.model.AttachmentInfo> attachmentInfoList = new ArrayList<cn.org.bjca.common.model.AttachmentInfo>();
		for (int i = 1; i < 3; i++) {
			cn.org.bjca.common.model.AttachmentInfo attachmentInfo = new cn.org.bjca.common.model.AttachmentInfo();
			attachmentInfo.setIndex(i);
			attachmentInfo.setAttachContent(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
			attachmentInfo.setEvidenceHash("Test");
			attachmentInfoList.add(attachmentInfo);
		}

		attachmentInfoMap.put(1, attachmentInfoList);
		anywriteSignInfo.setAttachmentInfo(attachmentInfoMap);
		List<PDFMergeInfo> pdfMergeInfoList = new ArrayList<PDFMergeInfo>();
		PDFMergeInfo pdfMergeInfo = new PDFMergeInfo();
		pdfMergeInfo.setDataSource(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
		pdfMergeInfo.setDocType(DocumentType.JPG);
		pdfMergeInfoList.add(pdfMergeInfo);
		anywriteSignInfo.setMergeInfo(pdfMergeInfoList);
		int[] rv = new int[2];
		byte[] pdf = sed.getPDFAnyWriteSignByObject(anywriteSignInfo, rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteSignByObjectOriginal.pdf"), pdf);
	}

	@After
	public void tearDown() throws Exception {

	}

	/**
	 * <p>老加密包多签名对象接口</p>
	 * @Description:
	 * @return:void
	 * @throws:
	 */
	@Test
	public void testAnyWriteSignByObjectListOriginal() throws Exception {
		List<AnywriteSignInfo> anywriteSignInfoList = new ArrayList<AnywriteSignInfo>();
		for (int i = 0; i < 3; i++) {
			AnywriteSignInfo anywriteSignInfo = new AnywriteSignInfo();
			byte[] dataSource = ClientUtil.readFileToByteArray(new File(testEncDataPath + "手写签名加密包.txt"));
			List<byte[]> dataSources = new ArrayList<byte[]>();
			dataSources.add(dataSource);
			anywriteSignInfo.setDataSource(dataSources);
			Map<Integer, List<cn.org.bjca.common.model.AttachmentInfo>> attachmentInfoMap = new HashMap<Integer, List<cn.org.bjca.common.model.AttachmentInfo>>();
			List<cn.org.bjca.common.model.AttachmentInfo> attachmentInfoList = new ArrayList<cn.org.bjca.common.model.AttachmentInfo>();
			for (int j = 1; j < 3; j++) {
				cn.org.bjca.common.model.AttachmentInfo attachmentInfo = new cn.org.bjca.common.model.AttachmentInfo();
				attachmentInfo.setIndex(j);
				attachmentInfo.setAttachContent(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
				attachmentInfo.setEvidenceHash("Test");
				attachmentInfoList.add(attachmentInfo);
			}

			attachmentInfoMap.put(1, attachmentInfoList);
			anywriteSignInfo.setAttachmentInfo(attachmentInfoMap);
			List<PDFMergeInfo> pdfMergeInfoList = new ArrayList<PDFMergeInfo>();
			PDFMergeInfo pdfMergeInfo = new PDFMergeInfo();
			pdfMergeInfo.setDataSource(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
			pdfMergeInfo.setDocType(DocumentType.JPG);
			pdfMergeInfoList.add(pdfMergeInfo);
			anywriteSignInfo.setMergeInfo(pdfMergeInfoList);
			anywriteSignInfoList.add(anywriteSignInfo);
		}
		int[] rv = new int[2];
		List<byte[]> pdfLists = sed.getPDFAnyWriteSignByObject(anywriteSignInfoList, rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		for (int i = 0; i < pdfLists.size(); i++) {
			ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testAnyWriteSignByObjectListOriginal_" + i + ".pdf"), pdfLists.get(i));
		}
	}

	/**
	 * <p>信手书老签章</p>
	 * @Description:
	 * @return:void
	 * @throws:
	 */
	@Test
	public void testGetUnitSignOriginal() throws IOException, ParameterInvalidException, UnkownException, ParameterOutRangeException, SVSConnectException {
		CloudUnitSignInfo cloudUnitSignInfo = new CloudUnitSignInfo();
		cloudUnitSignInfo.setDocContent(ClientUtil.readFileToByteArray(new File(testPdfFilePath)));
		cloudUnitSignInfo.setDocumentExtType(DocumentExtType.PDF);
		List<UnitSignInfo> unitSignInfoList = new ArrayList<UnitSignInfo>();
		UnitSignInfo unitSignInfo = new UnitSignInfo();
		unitSignInfo.setSignImage(ClientUtil.readFileToByteArray(new File(testImageFilePath)));
		unitSignInfo.setSignRuleType("0");
		KWRuleInfo kwRuleInfo = new KWRuleInfo();
		kwRuleInfo.setKW("的");
		kwRuleInfo.setKWXOffset("0");
		kwRuleInfo.setKWOffset("0");
		kwRuleInfo.setKWPos("0");
		kwRuleInfo.setKWYOffset("0");
		kwRuleInfo.setPageno("1");
		unitSignInfo.setKwRuleInfo(kwRuleInfo);
		unitSignInfo.setOrganAppName("3F89508445039559");
		unitSignInfoList.add(unitSignInfo);
		cloudUnitSignInfo.setUnitSignInfoList(unitSignInfoList);
		AnySignOutput anySignOutput = sed.getCloudSecurityEngine().excuteGetUnitSignPDF(cloudUnitSignInfo);
		System.out.println("状态码：" + anySignOutput.getStatusId());
		System.out.println("状态信息:" + errorCode2Info(anySignOutput.getStatusId()));
		Assert.assertEquals(anySignOutput.getStatusId(), 0);
		System.out.println("成功");
		ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testGetUnitSignOriginal.pdf"), anySignOutput.getPDFContent());

	}

	/**
	 * <p>信手书转换接口</p>
	 * @Description:
	 * @return:void
	 * @throws:
	 */
	@Test
	public void testGenPDFContentListOriginal() throws IOException, ParameterInvalidException, UnkownException, ParameterOutRangeException, SVSConnectException {
		PDFGenerateList pdfGenerateList = new PDFGenerateList();
		List<PDFGenerateInfo> generateInfoList=new ArrayList<PDFGenerateInfo>();
		PDFGenerateInfo generateInfo=new PDFGenerateInfo();
		generateInfo.setDocContent(ClientUtil.readFileToByteArray(new File(testHtmlFilePath)));
		generateInfo.setDocumentType(DocumentType.HTML);
		generateInfoList.add(generateInfo);

		PDFGenerateInfo generateInfo1 = new PDFGenerateInfo();
		generateInfo1.setDocumentType(DocumentType.XML);
		generateInfo1.setDocContent(ClientUtil.readFileToByteArray(new File(testXMLFilePath)));
		generateInfo1.setDocStyleTid("4DB8F54AD0CB2B6C");
		generateInfoList.add(generateInfo1);

		pdfGenerateList.setPDFGenerateInfo(generateInfoList);
		int[] rv = new int[2];
		List<byte[]> pdfLists = sed.getSecurityEngineDealIF().getGenPDFContentList(pdfGenerateList,rv);
		System.out.println("状态码:" + rv[0]);
		System.out.println("状态信息:" + errorCode2Info(rv[0]));
		Assert.assertEquals(0, rv[0]);
		System.out.println("成功,PDF保存路径:" + outPdfsFilePath);
		for (int i = 0; i < pdfLists.size(); i++) {
			ClientUtil.writeByteArrayToFile(new File(outPdfsFilePath + "testGenPDFContentListOriginal_" + i + ".pdf"), pdfLists.get(i));
		}

	}

	/**
	 * <p>验证接口</p>
	 * @Description:
	 * @return:void
	 * @throws:
	*/
	@Test
	public void testVerifyPDFOriginal() throws IOException, ParameterInvalidException, UnkownException, ParameterOutRangeException, SVSConnectException {
		int[] rv = new int[2];
		String verifyMessage = sed.verifyPDF(ClientUtil.readFileToByteArray(new File(testSignedPdfFilePath)), rv, "");
		VerifyResult verifyResult = JsonMapper.nonDefaultMapper().fromJson(verifyMessage,VerifyResult.class);
		System.out.println("服务状态码："+verifyResult.getStatusCode());
		System.out.println("服务状态信息：" + errorCode2Info(Integer.parseInt(verifyResult.getStatusCode())));
		Assert.assertEquals("200",verifyResult.getStatusCode());
		List<VerifyMessage> messageList = verifyResult.getMessage();
		for (VerifyMessage message : messageList) {
			System.out.println("验证状态码：" + message.getStatusCode());
			System.out.println("验证错误信息：" + errorCode2Info(Integer.parseInt(message.getStatusCode())));
			System.out.println("签名区域名称：" + message.getFieldName());
			System.out.println("签名时间：" + message.getSignDate());
			System.out.println("时间戳签名时间戳：" + message.getTimeStampDate());
			System.out.println("错误信息：" + Arrays.toString(message.getErrInfos()));
			System.out.println("证书DN项: " + Arrays.toString(message.getCertDNs()));
			System.out.println("扩展信息：" + message.getExtendsData());
			Assert.assertEquals("200",message.getStatusCode());
		}

	}
}
